package com.stgl.action;


import com.stgl.service.HomeService;
import com.stgl.util.MD5;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/home")
public class home {
    @Resource
    private HomeService homeService;

    @RequestMapping("getHomeData.html")
    @ResponseBody
    public Map<String,Object>getHomeData(HttpServletRequest request, HttpServletResponse response){
        Map<String,Object>gmap=new HashMap<String,Object>();
      /*  HttpSession session=((HttpServletRequest)request).getSession();
        if(request.getParameter("usid")!=null){
            gmap.put("usid",request.getParameter("usid").toString());
        }else{
            if(session.getAttribute("usid")!=null){
                gmap.put("usid",session.getAttribute("usid").toString());
            }
        }*/
        gmap=homeService.getHomeData();
        return gmap;
    }

    @RequestMapping("getSystemInfo.html")
    @ResponseBody
    public Map<String,Object>getSystemInfo(HttpServletRequest request, HttpServletResponse response){
        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap=homeService.getSystemInfo();
        return gmap;
    }


    @RequestMapping("updateSystemInfo.html")
    @ResponseBody
    public Boolean updateSystemInfo(HttpServletRequest request, HttpServletResponse response){

        String sfkqbm="";
        if(request.getParameter("sfkqbm")!=null){
            sfkqbm=request.getParameter("sfkqbm").toString().trim();
        }

        String bmjzrq="";
        if(request.getParameter("bmjzrq")!=null){
            bmjzrq=request.getParameter("bmjzrq").toString().trim();
        }

        String rxstart="";
        if(request.getParameter("rxstart")!=null){
            rxstart=request.getParameter("rxstart").toString().trim();
        }

        String rxend="";
        if(request.getParameter("rxend")!=null){
            rxend=request.getParameter("rxend").toString().trim();
        }


        String wxts="";
        if(request.getParameter("wxts")!=null){
            wxts=request.getParameter("wxts").toString().trim();
        }

        String qzbstart="";
        if(request.getParameter("qzbstart")!=null){
            qzbstart=request.getParameter("qzbstart").toString().trim();
        }
        String qzbend="";
        if(request.getParameter("qzbend")!=null){
            qzbend=request.getParameter("qzbend").toString().trim();
        }
        String xbstart="";
        if(request.getParameter("xbstart")!=null){
            xbstart=request.getParameter("xbstart").toString().trim();
        }
        String xbend="";
        if(request.getParameter("xbend")!=null){
            xbend=request.getParameter("xbend").toString().trim();
        }

        String zbstart="";
        if(request.getParameter("zbstart")!=null){
            zbstart=request.getParameter("zbstart").toString().trim();
        }
        String zbend="";
        if(request.getParameter("zbend")!=null){
            zbend=request.getParameter("zbend").toString().trim();
        }
        String dbstart="";
        if(request.getParameter("dbstart")!=null){
            dbstart=request.getParameter("dbstart").toString().trim();
        }
        String dbend="";
        if(request.getParameter("dbend")!=null){
            dbend=request.getParameter("dbend").toString().trim();
        }


        Map<String,Object>gmap=new HashMap<String,Object>();
        gmap.put("sfkqbm",sfkqbm);
        gmap.put("bmjzrq",bmjzrq);
        gmap.put("rxstart",rxstart);
        gmap.put("rxend",rxend);

        gmap.put("qzbstart",qzbstart);
        gmap.put("qzbend",qzbend);
        gmap.put("xbstart",xbstart);
        gmap.put("xbend",xbend);
        gmap.put("zbstart",zbstart);
        gmap.put("zbend",zbend);
        gmap.put("dbstart",dbstart);
        gmap.put("dbend",dbend);

        gmap.put("wxts",wxts);
        if(bmjzrq.equals("") && rxstart.equals("") && rxend.equals("")){
            return false;
        }
        boolean result=false;
        result=homeService.updateSystemInfo(gmap);
        return result;
    }



}
